<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	.tree-node {padding:0;}
	img {
		height:50px;
		width:50px;
	}
</style>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
	    		<legend>过滤条件</legend>
	    		<table style="width:100%">
	    			<tr>
	    				<td>话题标题:<input id="search_articleTitle" class="easyui-textbox" data-options="prompt:'请输入话题名称'" ></td>
	    				<td>话题作者:<input id="search_user" class="easyui-textbox" data-options="prompt:'请输入作者'" ></td>
	    				<td>
	    					话题类型:
	    					<select id="search_articleType" class="easyui-combobox" data-options="width:60,panelHeight:100">
	    						<option></option>
	    						<option value="1">短文</option>
	    						<option value="2">长文</option>
	    					</select>
	    				</td>
	    				<td>
	    					是否可用:
	    					<select id="search_enabled" class="easyui-combobox" name="enabled" data-options="width:50,panelHeight:60">
	    						<option> </option>
	    						<option value="1">是</option>
	    						<option value="0">否</option>
	    					</select>
	    				</td>
	    				<td><a id="a_searchTag" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
	    				<td>
	    					<a id="a_clearn" class="easyui-linkbutton" iconCls="icon-undo">清除</a>
	    				</td>
	    			</tr>
	    		</table>
	  		</fieldset>
		</div>
  		<div data-options="region:'center',border:false" style="padding-bottom: 33px">
  			<div id="topic_grid_toolbar" class="toolbar"></div>
            <table id="topic_grid"></table>
		</div>
		
	</div>
	<script>
		$(function(){
			$('#topic_grid_toolbar').toolbar({buttons:[
	           	{name:'add',iconCls:'icon-add',text:'添加话题'},
	      	],handler:handler});
			
			$('#topic_grid').datagrid({
		    	url:'page',
	    		pagination:true,
	    		pageSize:20,
	    		singleSelect:true,
	    		rownumbers:false,
	    		striped:true,
	    		fit:true,
	    		fitColumns:true,
	    		toorbar:'#toolbar_articleTable',
	    		columns:[[
	    			{field:'id',title:'编号',width:5},
	    			{field:'articleTitle',title:'文章标题',width:30},
	        		{field:'nickname',title:'作者',width:10},
	        		{field:'articleType',title:'类型',width:10,formatter:function(v,r,i){
	        			var type ="";
	        			if(r.articleType == "1"){type ="短文"}else if(r.articleType == "2"){type ="长文"}
	        			return type;
	        		}},
	        		{field:'countView',title:'浏览量',width:5},
	        		{field:'countPraise',title:'点赞量',width:5},
	        		{field:'countShare',title:'分享量',width:5},
	        		{field:'countCollect',title:'收藏量',width:30},
	        		{field:'enabled',title:'删除标记',formatter:function(v,r,i){
	        			var show = '删除';
	        			if(r.enabled){
	        				show = '正常';
	        			}
	        			return show;
	        		}},
	        		{field:'createdDt',title:'创建时间'},
	        		{field:'-',title:'操作',align:'center',formatter:function(v,r,i){
	        			/* var action = '<a href="#" onclick="toEdit('+r.id+');">编辑</a>&nbsp;&nbsp;'; */
	        			var action = '';
	        			if(r.enabled){
	        				action = action+'<a href="#" onclick ="updateEnabled('+r.id+');">禁用</a>';
	        			}else{
	        				action = action+'<a href="#" onclick="updateEnabled('+r.id+');">启用</a>';
	        			}
	        			action = action+'&nbsp;&nbsp;<a href="#">查看</a>';
	        			
						return action;
					}}
	    		]],
	    		view: detailview,
	    	    detailFormatter: function(rowIndex, rowData){
	    	    	var details;
	    	    	if(rowData.articleType == '1'){
	    	    		details = '<table><tr>' +
    	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleTitle+'</td>' +
    	                '</tr></table>';
	    	    	}else if(rowData.articleType == '2'){
	    	    		details = '<table><tr>' +
    	                '<td rowspan=2 style="border:0,height:50px;">'+rowData.articleContent+'</td>' +
    	                '</tr></table>';
	    	    	}
	    	        return details;
	    	    }
			 });
			
			
			$("#a_searchTag").click(function(){
				reloadDate();
			});
			$("#a_clearn").click(function(){
				resetData();
			});
				
			function reloadDate(){
				var item = getItem();
				$('#topic_grid').datagrid({ queryParams: item});   //点击搜索
			}
			
			function resetData(){
				$("#search_user").textbox("setValue","");
				$("#search_articleTitle").textbox("setValue","");
				$("#search_articleType").combobox("setValue","");
				$("#search_enabled").combobox("setValue","");
				reloadDate();
			}
		});
		
		
		 //过滤条件参数
		function getItem(){
			var userName = $.trim($("#search_user").textbox("getValue"));
			var articleTitle = $.trim($("#search_articleTitle").textbox("getValue"));
			var articleType = $.trim($("#search_articleType").combobox("getValue"));
			var enabled = $.trim($("#search_enabled").combobox("getValue"));
			var searchItem = {};
			if(userName.length>0){
				searchItem.userName=userName;
			}
			if(articleTitle.length>0){
				searchItem.articleTitle=articleTitle;
			}
			if(articleType.length>0){
				searchItem.articleType=articleType;
			}
			if(enabled.length>0){
				searchItem.enabled=enabled;
			}
			return searchItem;
		}
		
		function handler() {
			if(this.name == 'search') return toSearch();
			var item = $('#group_grid').datagrid('getSelected');
			if(!item) return;
			if(this.name == 'add') return toAdd(item);
			switch(this.name) {
			case 'addSub': add(item);break;
			case 'edit': toEdit(item);break;
			}
		}
		function toAdd(item){
			show({code:'topic_grid_add',title:'编辑话题信息',iconCls:'icon-edit',uri:'addTopic?groupId='+item.id,width:800,height:600,
				options : {
					success : function(data) { 
						$('#topic_grid').datagrid('reload'); 
					}
				}
			});
		}
		function toEdit(id) {
			show({code:'topic_grid_edit',title:'编辑话题信息',iconCls:'icon-edit',uri:'edit?id='+id,width:800,height:600,
				options : {
					success : function(data) { 
						$('#topic_grid').datagrid('reload'); 
					}
				}
			});
		}
		
		function toDel(id) {
			var item = $('#group_grid').datagrid('getSelected');
			var param = {};
	    	param.groupId = item.id;
	    	param.userId = id;
			$confirm('您确定要删除该成员吗？',function() {
				$.post('deleteBygroupIdAndUserId',param,function(r) {
					if(r.code <= 0) return $error(r.msg);
					$('#topic_grid').datagrid('reload');
					$prompt('删除成功');
				},'json');
			});
		}
		
		function updateEnabled(id){
			var parms = {};
			parms.id = id;
			parms.enabled = true;
			$.post('updateEnabled',parms,function(r){
				if(r.code>0){
					$('#topic_grid').datagrid('reload'); 
				};
			},'json');
		}
		
	</script>
  </body>
</html>